#include <iostream>
#include <queue>
#include <vector>

struct sigNode
{
    int x;
    int y;
    int sig;
};

int direction_vec[4][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};

int main()
{
    int m, n;
    std::cin >> m >> n;

    std::queue<sigNode> sq;
    std::vector<std::vector<int>> sigmap(m, std::vector<int>(n, 0));
    std::vector<std::vector<bool>> usemap(m, std::vector<bool>(n, false));
    for (int i = 0; i < m; i++)
    {
        for (int j = 0; j < n; j++)
        {
            std::cin >> sigmap[i][j];
            if (sigmap[i][j] > 0)
            {
                sq.push({j, i, sigmap[i][j]});
                usemap[i][j] = true;
            }
            if (sigmap[i][j] < 0)
            {
                usemap[i][j] = true;
            }
        }
    }

    int a, b;
    std::cin >> a >> b;
    int signal = 0;

    while (!sq.empty())
    {
        auto sn = sq.front();
        sq.pop();
        if (sn.x == b && sn.y == a)
        {
            signal = sn.sig;
            break;
        }

        for (int i = 0; i < 4; i++)
        {
            int x = sn.x + direction_vec[i][0];
            int y = sn.y + direction_vec[i][1];
            int sig = sn.sig - 1;

            if (x >= 0 && x < n && y >= 0 && y < m && !usemap[y][x] && sig > 0)
            {
                usemap[y][x] = true;
                sq.push({x, y, sig});
            }
        }
    }

    std::cout << signal << std::endl;

    return 0;
}